/**
 * Created by weng on 2017/6/24.
 */

var getNewsInfo = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getNewsInfo',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{
                for(var i in data.info){
                    console.log(data.info[i]);
                    $("#newsTitle"+data.info[i].topId).text(data.info[i].title);
                    $("#newsTitle"+data.info[i].topId).attr('href','/news/news1?id='+data.info[i].topId);

                    $("#newsContent"+data.info[i].topId).text(data.info[i].topContent);
                    $("#newsContent"+data.info[i].topId).attr('href','/news/news1?id='+data.info[i].topId);

                    $("#newsTime"+data.info[i].topId).text(data.info[i].time);
                    $("#newsTime"+data.info[i].topId).attr('href','/news/news1?id='+data.info[i].topId);

                }
            }
        }
    });
}


var getPhoneNewsInfo = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getNewsInfo',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{

                var html = "";
                for(var i in data.info){
                    var id= "newsTitleHref" + data.info[i].topId
                    var url = '/phone/new1?id='+data.info[i].topId;
                    html += '<a id= "' + id + '" href="'+ url +'" class=""><span id="newsTitle1">' +data.info[i].title + '</span></a>'
                }
                $("#newInfo").append(html);

            }
        }
    });
}


var getNewsInfoDetail = function(){
    var id = $("#topId").val();
    console.log("获取信息",id);
    $.ajax({
        url:'/controller/getNewsInfoDetail',
        type:'post',
        dataType:'json',
        data:{id:id},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{
                for(var i in data.info){
                    console.log(data.info[i]);
                    document.title = data.info[i].title;

                    $(".newsDetailTitle").text(data.info[i].title);
                    console.log(detailContent)

                    var detailContent = data.info[i].detailContent.replace(/\r\n/g,"<br/>");
                    detailContent = detailContent.substring(0,detailContent.length - 1);
                    var html = ''
                    html +=  '<span style="font-family:微软雅黑;font-size:14px;"></span>';
                    html += ' <p>'
                    html += '  <span style="font-family:微软雅黑;font-size:14px;">'
                    html += detailContent
                    html += '<br></span>'
                    html += ' </p>'
                    html += '<div><span style="font-family:微软雅黑;font-size:14px;"><br></span></div>'
                        console.log("html is:",html);
                    $("#newsDetailContent").append(html);
                }
            }
        }
    });
}


var getPhoneNewsInfoDetail = function(){
    var id = $("#topId").val();
    console.log("获取信息",id);
    $.ajax({
        url:'/controller/getNewsInfoDetail',
        type:'post',
        dataType:'json',
        data:{id:id},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{
                for(var i in data.info){
                    console.log(data.info[i]);
                    document.title = data.info[i].title;

                    $(".newsDetailTitle").text(data.info[i].title);
                    $("#newstime").text("时间："+ data.info[i].time);

                    var detailContent = data.info[i].detailContent.replace(/\r\n/g,"<br />");
                    detailContent = detailContent.substring(0,detailContent.length - 1);
                    var html = ''
                    html +=  '<span style="font-family:微软雅黑;font-size:14px;"></span>';
                    html += ' <p>'
                    html += '  <span style="font-family:微软雅黑;font-size:14px;">'
                    html += detailContent
                    html += '<br></span>'
                    html += ' </p>'
                    html += '<div><span style="font-family:微软雅黑;font-size:14px;"><br></span></div>'
                        console.log("html is:",html);
                    $("#newsDetailContent").append(html);
                }
            }
        }
    });
}


var getAboutAsInfo = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getAboutAsInfo',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{
                for(var i in data.info){
                    console.log(data.info[i]);
                    if(data.info[i].id == 0)
                        $("#compneyInfo").html(data.info[i].content);
                    else if(data.info[i].id == -1)
                        $("#bossInfo").html(data.info[i].content);
                    else{
                        $("#info"+data.info[i].id).html(data.info[i].content);
                    }

                }
            }
        }
    });
}


var getindexContent = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getindexContent',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{
                for(var i in data.info){
                    console.log(data.info[i]);
                    $("#indexContent").html(data.info[i].content);
                }
            }
        }
    });
}


var getContactInfo = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getContactInfo',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{

                for(var i in data.info){
                    switch (data.info[i].id){
                        case 1 :
                            $("#address").html(data.info[i].content);
                            break;
                            case 2 :
                            $("#phone").html(data.info[i].content);
                            break;
                            case 3 :
                            $("#web").html(data.info[i].content);
                            break;
                            case 4 :
                            $("#mobile").html(data.info[i].content);
                            case 5 :
                                $("#addressUrl").attr("href",data.info[i].content);
                            break;
                    }
                }
            }
        }
    });
}




//获取pc端首页信息getNewsInfo
var getPcIndexInfo = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getPcindexContent',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{

                for(var i in data.info){
                    $("#type"+data.info[i].typeName  +"Title"+data.info[i].id).text(data.info[i].title);
                    $("#type"+data.info[i].typeName  +"Content"+data.info[i].id).text(data.info[i].content);
                }
            }
        }
    });
}




//获取pc端关于我们
var getPcAboutUs = function(){
    console.log("获取信息");
    $.ajax({
        url:'/controller/getPcindexContent',
        type:'post',
        dataType:'json',
        data:{},
        success:function(data){
            if(data.code != 200){
                return ;
            }else{

                for(var i in data.info){
                    $("#type"+data.info[i].typeName  +"Title"+data.info[i].id).text(data.info[i].title);
                    $("#type"+data.info[i].typeName  +"Content"+data.info[i].id).text(data.info[i].content);
                }
            }
        }
    });
}